/**
 * Created by wangfan on 2017/6/9.
 */

$(function () {

    $.ajax({
        url: '/commis/api/user/currentUser',
        type: "GET",
        async: false,
        dataType: 'json',
        data: {},
        success: function (response) {
            if (response.status == 0) {
                // console.log("用户存在");
                user = response.data;
                userTypeId = user.userTypeId;
                var  communtityId=user.community.communtityId;
                if (userTypeId == 4) {
                    var communityName = user.community.communityName;
                    $("#communityName").val(communityName);
                    $('#ppDate').val(getNowFormatDateShort())

                }

                $.ajax({
                    url: '/commis/api/image/getImagePathForCom',
                    type: "POST",
                    async: false,
                    dataType: 'json',
                    data: {communtityId:communtityId},
                    success: function (response) {
                        if (response.status == 0) {
                            $("#yinzhang").css({"width":"790px","background":"url(comImg/"+response.data.yinzhangImg+") no-repeat","background-position":"240px 70px"});

                            // $("#yinzhang").attr('src',"comImg/"+response.data.yinzhangImg);
                            $("#jwhzrImg").attr('src',"signImg/"+response.data.signImg);
                            // alert(response.data.yinzhangImg);

                        } else if (response.status == 1) {
                            alert("获取图片出错");

                        }
                    }, error: function (msg) {
                        alert("获取图片出错");
                    }
                })
            } else if (response.status == 1) {
                alert("登录用户已经过期，请重新登录");
                window.parent.location.href = "../../login.html";
            }
        }, error: function (msg) {
            alert("登录用户已经过期，请重新登录");
            window.parent.location.href = "../../login.html";
        }
    })

    $('#ppDate').datetimepicker({
        language: 'zh-CN',
        format: "yyyy-mm-dd",
        minView: "month",
        autoclose: true,
        todayBtn: true,


    }).on('changeDate show', function(e) {
        // $('#dataForm').bootstrapValidator('revalidateField', 'ppDate');
    });

    // var ue = UE.getEditor('container');

    $("#sctime").text(formatStringyyyyMMddTochinese(getNowFormatDate()));


    $("#save").on("click", function () {

        var ppName  =$("input[name='ppName']").val();
        var ppDate  =$("input[name='ppDate']").val();
        var ppDetail  =$("textarea[name='ppDetail']").val();
        var amount  =$("input[name='amount']").val();

        if(!ppName){
            alert("项目名称不能为空");
            return false;
        }
        if(!ppDate){

            alert("项目时间不能为空");
            return false;

        }
        if(!ppDetail){

            alert("主要内容不能为空");
            return false;

        }
        if(!amount){




            alert("申请金额小写不能为空");
            return false;

        }else{
            var reg=/\d+(\.\d+)?/;

            if(!reg.test(amount)){
                alert("申请金额小写必选为double型！");
                return false;

            }

        }
        if (true) {

            $.ajax({
                type: "POST",
                url:"/commis/api/fund/muticreate",
                data:decodeURIComponent($('#dataForm').serialize(),true),
                async: false,
                error: function(request) {
                    alert("申报失败，请检查填写内容是否正确");
                },
                success: function(response) {
                    //接收后台返回的结果
                    if (response.status==0) {
                        confirm("申请成功，是否关闭当前窗口？")
                        window.parent.document.getElementById("tabCloseCurrent").click();
                    } else if (response.status==1) {
                        alert("请检查是否填写正确!");
                    }

                }
            });



            //提交不了
            // $("#submitter").submit();
        }else{
            alert("数据填写不正确，请按照提示信息修改后提交");
        }


    });

    $("input[name='hasDetail']").click(function () {
        if ($(this).val() == "1") {


            $("#externalLink").show();
        }else {
            $("#externalLink").hide();



        }
    });


})
//设置框架
$(function () {
    $("#page_style").frame({
        float: 'left',
        menu_nav: '.Quick_operation',
        color_btn: '.skin_select',
        Sellerber_menu: '.list_content',
        Sellerber_header: '.Sellerber_header',
    });
});
$("#iframe_box").niceScroll({
    cursorcolor: "#888888",
    cursoropacitymax: 1,
    touchbehavior: false,
    cursorwidth: "5px",
    cursorborder: "0",
    cursorborderradius: "5px"
});
/*********************/
require.config({
    paths: {
        echarts: './js/dist'
    }
});